##开启事务
BEGIN;
SET NAMES utf8mb4;

-- ------------------------> 正式开始写 SQL 语句 <------------------------
INSERT INTO `hair_salon`.`email_template` (`id`, `template_code`, `template_content`, `msg_title`, `is_deleted`,
                                           `create_time`, `update_time`)
VALUES ('1572951144690454532', 'SYSTEM_ERROR',
        '您好, #{#receiveName}: <br/>&emsp;&emsp;原宿微信小程序&emsp;系统于&emsp;#{#errorTime}&emsp;发生异常,错误信息为:<br/>&emsp;&emsp;&emsp;&emsp;<code>#{#errorMsg}</code><br/>&emsp;&emsp;请尽快登录服务器查看详情并处理。</pre><br/>感谢您的使用,如有打扰, 请忽略此邮件。',
        'MyHairSalon系统错误', 0, '2025-01-14 16:56:49', '2025-01-14 16:56:49');

CREATE TABLE `hair_salon`.`voucher_member`
(
    `id`             varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci  NOT NULL COMMENT '数据ID',
    `shop_id`        varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci  NULL     DEFAULT NULL COMMENT '店铺ID',
    `member_id`      varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci  NOT NULL COMMENT '会员ID',
    `voucher_id`     varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci  NOT NULL COMMENT '代金券ID',
    `issue_time`     datetime                                                      NULL     DEFAULT NULL COMMENT '下发时间',
    `issue_user`     varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci  NULL     DEFAULT NULL COMMENT '下发用户',
    `use_flag`       tinyint(1)                                                    NOT NULL DEFAULT 0 COMMENT '使用状态(0-未使用, 1-已使用)',
    `use_time`       datetime                                                      NULL     DEFAULT NULL COMMENT '使用时间',
    `voucher_name`   varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL     DEFAULT NULL COMMENT '代金券名称',
    `voucher_amount` decimal(10, 2)                                                NULL     DEFAULT NULL COMMENT '代金券金额',
    `validity_start` date                                                          NULL     DEFAULT NULL COMMENT '有效期-开始',
    `validity_end`   date                                                          NULL     DEFAULT NULL COMMENT '有效期-结束',
    `voucher_status` tinyint(1)                                                    NOT NULL DEFAULT 0 COMMENT '代金券状态(0-未生效, 1-生效中, 2-已过期)',
    `remark`         varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL     DEFAULT NULL COMMENT '备注',
    `is_deleted`     tinyint(1)                                                    NOT NULL DEFAULT 0 COMMENT '逻辑删除：1(已删除) 0(未删除)',
    `create_time`    datetime                                                      NULL     DEFAULT NULL COMMENT '创建时间',
    `update_time`    datetime                                                      NULL     DEFAULT NULL COMMENT '修改时间',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT = '会员代金券表'
  ROW_FORMAT = Dynamic;

ALTER TABLE `hair_salon`.`voucher_member`
    ADD UNIQUE INDEX `id_index` (`id`) USING BTREE,
    ADD INDEX `shop_id_index` (`shop_id`) USING BTREE,
    ADD INDEX `member_id_index` (`member_id`) USING BTREE,
    ADD INDEX `voucher_id_index` (`voucher_id`) USING BTREE;

ALTER TABLE `hair_salon`.`expense_bill`
    ADD COLUMN `vou_mem_id` varchar(50) NULL COMMENT '代金券ID' AFTER `gift_price`;

ALTER TABLE `hair_salon`.`voucher_member`
    ADD COLUMN `top_up_id` varchar(50) NOT NULL COMMENT '充值记录ID' AFTER `voucher_id`;
-- ------------------------> 正式结束写 SQL 语句 <------------------------
##提交事务
COMMIT;

## 如遇错误, 执行以下sql
## ROLLBACK;